package thread;

import java.util.Scanner;

public class Demo24 {
    private static Object lock = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (lock) {
                System.out.println("t1 wait begin");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1 wait end");
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (lock) {
                System.out.println("t2 wait begin");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t2 wait end");
            }
        });

        Thread t3 = new Thread(() -> {
            synchronized (lock) {
                System.out.println("t3 wait begin");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t3 wait end");
            }
        });

        Thread t4 = new Thread(() -> {
            System.out.println("t4 notifyAll begin");
            Scanner sc = new Scanner(System.in);
            sc.next();
            synchronized (lock) {
                lock.notifyAll();
            }
            System.out.println("t4 notifyAll end");
        });

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
